package com.hue.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hue.entity.CrmBanner;
import com.hue.mapper.CrmBannerMapper;
import com.hue.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author 姚凤桥
 * @since 2021-07-03
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {
    //查询前两条记录并按照sort排序
    @Cacheable(value = "banner",key = "'indexBanners'") //根据方法返回的结果对数据进行缓存，如果下次查询时Redis中有数据，就从缓存中查询，如果没有就执行方法
    public List<CrmBanner> findOrderBySort(){
        QueryWrapper<CrmBanner> wrapper =new QueryWrapper();
        wrapper.orderByAsc("sort");
        //拼接sql语句，有sql注入的风险
        wrapper.last(" limit 2");
        List<CrmBanner> banners = this.list(wrapper);
        return banners;
    }
}
